package com.kaka.bus.view.dialog;

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.SpannableStringBuilder;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.kaka.bus.R;
import com.kaka.bus.listener.Listener;
import com.kaka.bus.util.U;

/**
 * Created by OnionMac on 2018/1/2.
 */

public class TipsDialog extends BaseDialog {

    public static final int TYPE_SINGLE = 1;
    public static final int TYPE_TWO = 2;
    public static final int TYPE_THREE = 3;

    private int mType;
    private ImageView mClose;
    private ImageView mImg;
    private TextView mInfo;
    private View mTwo;
    private TextView mSingle;
    private TextView mLeft;
    private TextView mRight;
    private TextView mDanger;
    private Context mContext;
    public TipsDialog(@NonNull Context context,int type) {
        super(context);
        mType = type;

        mContext = context;
    }

    private Listener.OnNormalAlertDialogSingleClickListener mSingleClickListener;

    private Listener.OnNormalAlertDialogChooseClickListener mChooseClickListener;

    public void setSingleClickListener(Listener.OnNormalAlertDialogSingleClickListener singleClickListener) {
        mSingleClickListener = singleClickListener;
    }

    public void setChooseClickListener(Listener.OnNormalAlertDialogChooseClickListener chooseClickListener) {
        mChooseClickListener = chooseClickListener;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_tips;
    }

    @Override
    protected void initView() {
        mClose = findViewById(R.id.dialog_tips_close);
        mImg = findViewById(R.id.dialog_tips_img);
        mInfo = findViewById(R.id.dialog_tips_info);
        mTwo = findViewById(R.id.dialog_tips_bottom_two);
        mSingle = findViewById(R.id.dialog_tips_bottom_single);
        mLeft = findViewById(R.id.dialog_tips_bottom_left);
        mRight = findViewById(R.id.dialog_tips_bottom_right);
        mDanger = findViewById(R.id.dialog_tips_danger);
        mClose.setOnClickListener(v -> {
            dismiss();
        });

        mSingle.setOnClickListener(v -> {
            if(mSingleClickListener != null){
                mSingleClickListener.singleClick();
            }
        });

        mLeft.setOnClickListener(v -> {
            if(mChooseClickListener != null){
                mChooseClickListener.onLeft();
            }
        });

        mRight.setOnClickListener(v -> {
            if(mChooseClickListener != null){
                mChooseClickListener.onRight();
            }
        });
    }

    /**
     * 设置数据
     * @param info
     */
    public void setData(String info){

    }

    @Override
    public void show() {
        super.show();
        if(mType == TYPE_SINGLE){
            mSingle.setVisibility(View.VISIBLE);
            mTwo.setVisibility(View.GONE);
            mImg.setImageResource(R.mipmap.qianyuewancheng);
        }else if(mType == TYPE_TWO){
            mSingle.setVisibility(View.GONE);
            mTwo.setVisibility(View.VISIBLE);
            mImg.setImageResource(R.mipmap.shenghechenggong);
        }else if(mType == TYPE_THREE){
            mSingle.setVisibility(View.GONE);
            mTwo.setVisibility(View.VISIBLE);
            mImg.setImageResource(R.mipmap.qianyue);
            mDanger.setVisibility(View.VISIBLE);

        }
    }

    public void setPactInfo(){
        mLeft.setText("取消");
        mRight.setText("签约");
        mInfo.setText("根据信用等级不同将进行快速放款,请注意接听抽样审核电话。");
    }

    public void setShenheSuccess(String money){
        String tips = U.connectString("经审核,您获批的申请额度为",money,"元,若要申请更高额度,请继续认证!");
        SpannableStringBuilder spannable = U.toRichText(tips, mContext.getResources().getColor(R.color.red_money), tips.indexOf("为")+1, tips.indexOf("元")+1);
        mInfo.setText(spannable);
    }

    @Override
    protected int moveY() {
        return -50;
    }

    @Override
    protected double getWidthPer() {
        return 0.8;
    }
}
